home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / once_routine_pool.e < prev    next >
Text File  |  1998-01-16  |  6KB  |  277 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class ONCE_ROUTINE_POOL
  17.    --
  18.    -- Unique global object in charge of runnable once routines.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.    
  25.    procedure_list: FIXED_ARRAY[RUN_FEATURE_5] is
  26.       once
  27.      !!Result.with_capacity(32);
  28.       end;
  29.    
  30.    procedure_flag_list: FIXED_ARRAY[INTEGER];
  31.  
  32.    function_list: FIXED_ARRAY[RUN_FEATURE_6] is
  33.       once
  34.      !!Result.with_capacity(32);
  35.       end;
  36.    
  37.    function_flag_list: FIXED_ARRAY[INTEGER];
  38.  
  39.    flag_list: FIXED_ARRAY[INTEGER] is
  40.       once
  41.      !!Result.with_capacity(32);
  42.       end;
  43.  
  44. feature {RUN_FEATURE_5}
  45.  
  46.    add_procedure(rf5: RUN_FEATURE_5) is
  47.       require
  48.      rf5 /= Void
  49.       do
  50.      check
  51.         not procedure_list.has(rf5)
  52.      end;
  53.      procedure_list.add_last(rf5);
  54.       end;
  55.    
  56. feature {RUN_FEATURE_6}
  57.  
  58.    add_function(rf6: RUN_FEATURE_6) is
  59.       require
  60.      rf6 /= Void
  61.       do
  62.      check
  63.         not function_list.has(rf6)
  64.      end;
  65.      function_list.add_last(rf6);
  66.       end;
  67.    
  68. feature {GC_HANDLER}
  69.  
  70.    gc_mark_in(str: STRING) is
  71.       local
  72.      i, id: INTEGER;
  73.      rf6: RUN_FEATURE_6;
  74.      t: TYPE;
  75.       do
  76.      if function_list.count > 0 then
  77.         from
  78.            i := function_list.upper;
  79.         until
  80.            i < 0
  81.         loop
  82.            rf6 := function_list.item(i);
  83.            t := rf6.result_type;
  84.            if t.need_gc_mark_function then
  85.           id := t.id;
  86.           if t.is_reference then
  87.              str.append(fz_c_if_neq_null);
  88.              rf6.once_result_in(str);
  89.              str.extend(')');
  90.              str.append(fz_gc_mark);
  91.              id.append_in(str);
  92.              str.extend('(');
  93.              str.append(fz_cast_void_star);
  94.              rf6.once_result_in(str);
  95.              str.extend(')');
  96.           elseif t.is_user_expanded then
  97.           else
  98.           end;
  99.           str.append(fz_00);
  100.            end;
  101.            i := i - 1;
  102.         end;
  103.      end;
  104.  
  105.       end;
  106.  
  107. feature {JVM}
  108.  
  109.    fields_count: INTEGER;
  110.  
  111.    jvm_define_fields is
  112.       local
  113.      byte_idx, idx_flag, i: INTEGER;
  114.      rf5: RUN_FEATURE_5;
  115.      rf6: RUN_FEATURE_6;
  116.      bf: E_FEATURE;
  117.      name_list: FIXED_ARRAY[INTEGER];
  118.       do
  119.      !!name_list.with_capacity(fields_count);
  120.      if function_list.count > 0 then
  121.         from
  122.            i := function_list.upper;
  123.            byte_idx := constant_pool.idx_uft8(fz_41);
  124.         until
  125.            i < 0
  126.         loop
  127.            rf6 := function_list.item(i);
  128.            bf := rf6.base_feature;
  129.            idx_flag := idx_name_for_flag(bf);
  130.            if name_list.fast_has(idx_flag) then
  131.            else
  132.           name_list.add_last(idx_flag);
  133.           -- ---------- Static field for flag :
  134.           field_info.add(9,idx_flag,byte_idx);
  135.           -- ---------- Static field for result :
  136.           field_info.add(9,
  137.                  idx_name_for_result(bf),
  138.                  idx_descriptor(rf6.result_type.run_type));
  139.            end;
  140.            i := i - 1;
  141.         end;
  142.      end;
  143.      if procedure_list.count > 0 then
  144.         from
  145.            i := procedure_list.upper;
  146.            byte_idx := constant_pool.idx_uft8(fz_41);
  147.         until
  148.            i < 0
  149.         loop
  150.            rf5 := procedure_list.item(i);
  151.            bf := rf5.base_feature;
  152.            idx_flag := idx_name_for_flag(bf);
  153.            if name_list.fast_has(idx_flag) then
  154.            else
  155.           name_list.add_last(idx_flag);
  156.           -- ---------- Static field for flag :
  157.           field_info.add(9,idx_flag,byte_idx);
  158.            end;
  159.            i := i - 1;
  160.         end;
  161.      end;
  162.       end;
  163.  
  164.    jvm_initialize_fields is
  165.       local
  166.      i: INTEGER;
  167.       do
  168.      if flag_list.count > 0 then
  169.         from
  170.            i := flag_list.upper;
  171.         until
  172.            i < 0
  173.         loop
  174.            -- Set once flag :
  175.            code_attribute.opcode_iconst_0;
  176.            code_attribute.opcode_putstatic(flag_list.item(i),-1);
  177.            i := i - 1;
  178.         end;
  179.      end;
  180.       end;
  181.  
  182. feature {RUN_FEATURE_5,RUN_FEATURE_6}
  183.  
  184.    idx_fieldref_for_flag(rf: RUN_FEATURE): INTEGER is
  185.       require
  186.      rf /= Void
  187.       do
  188.      prepare_flag(rf.base_feature);
  189.      Result := constant_pool.idx_fieldref3(jvm_root_class,
  190.                            flag_string,
  191.                            fz_41);
  192.       end;
  193.  
  194. feature {RUN_FEATURE_6}
  195.  
  196.    idx_fieldref_for_result(rf6: RUN_FEATURE_6): INTEGER is
  197.       require
  198.      rf6 /= Void
  199.       do
  200.      prepare_result(rf6.base_feature);
  201.      prepare_descriptor(rf6.result_type.run_type);
  202.      Result := constant_pool.idx_fieldref3(jvm_root_class,
  203.                            result_string,
  204.                            descriptor_string);
  205.       end;
  206.  
  207.  
  208. feature {NONE}
  209.  
  210.    idx_descriptor(rt: TYPE): INTEGER is
  211.       require
  212.      rt /= Void
  213.       do
  214.      prepare_descriptor(rt);
  215.      Result := constant_pool.idx_uft8(descriptor_string);
  216.       end
  217.  
  218.    idx_name_for_result(bf: E_FEATURE): INTEGER is
  219.       require
  220.      bf /= Void
  221.       do
  222.      prepare_result(bf);
  223.      Result := constant_pool.idx_uft8(result_string);
  224.       end
  225.  
  226.    idx_name_for_flag(bf: E_FEATURE): INTEGER is
  227.       require
  228.      bf /= Void
  229.       do
  230.      prepare_flag(bf);
  231.      Result := constant_pool.idx_uft8(flag_string);
  232.       end
  233.  
  234.    flag_string: STRING is
  235.       once
  236.      !!Result.make(32);
  237.       end;
  238.  
  239.    prepare_flag(bf: E_FEATURE) is
  240.       do
  241.      flag_string.clear;
  242.      flag_string.extend('f');
  243.      bf.base_class.id.append_in(flag_string);
  244.      flag_string.append(bf.first_name.to_key);
  245.       end;
  246.  
  247.    result_string: STRING is
  248.       once
  249.      !!Result.make(32);
  250.       end;
  251.  
  252.    prepare_result(bf: E_FEATURE) is
  253.       do
  254.      result_string.clear;
  255.      result_string.extend('r');
  256.      bf.base_class.id.append_in(result_string);
  257.      result_string.append(bf.first_name.to_key);
  258.       end;
  259.  
  260.    prepare_descriptor(rt: TYPE) is
  261.       do
  262.      descriptor_string.clear;
  263.      if rt.is_reference then
  264.         descriptor_string.append(jvm_root_descriptor)
  265.      else
  266.         rt.jvm_descriptor_in(descriptor_string)
  267.      end;     
  268.       end;
  269.  
  270.    descriptor_string: STRING is
  271.       once
  272.      !!Result.make(32);
  273.       end;
  274.  
  275. end -- ONCE_ROUTINE_POOL
  276.  
  277.